﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FusionDotNet
{
    /// <summary>
    /// Implementation of IAsyncResult using in the BeginExecute...EndExecute asynchronous implementation.
    /// </summary>
    public class FusionAsyncResult : IAsyncResult
    {
        private object state;

        internal FusionAsyncResult(object state)
        {
            this.state = state;
            AsyncWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset);
        }

        /// <summary>
        /// Gets a user-defined object that qualifies or contains information about an
        /// asynchronous operation.
        /// </summary>
        public object AsyncState
        {
            get { return state; }
        }

        /// <summary>
        /// Gets a System.Threading.WaitHandle that is used to wait for an asynchronous
        /// operation to complete.
        /// </summary>
        public System.Threading.WaitHandle AsyncWaitHandle { get; internal set; }

        /// <summary>
        /// When True indicates that EndInvoke was called immediately after the call to BeginInvoke. 
        /// The system will not raise the call-back event specified in the call to BeginInvoke.
        /// </summary>
        public bool CompletedSynchronously { get; internal set; }

        /// <summary>
        /// Indicates that the asynchronous operation has completed.
        /// </summary>
        public bool IsCompleted { get; internal set; }
    }
}
